#include <iostream>
using std::cout;
using std::endl;

class Base{
public:
    Base(long base)
    : _base(base)
    {}

    Base(const Base & rhs)
    : _base(rhs._base)
    {
        cout << "Base的拷贝构造" << endl;
    }

    Base & operator=(const Base & rhs){
        _base = rhs._base;
        cout << "Base的赋值运算符函数" << endl;
        return *this;
    }

protected:
    long _base = 10;
};


class Derived
: public Base
{
public:
    Derived(long base, long derived)
    : Base(base)
    , _derived(derived)
    {}

    Derived(const Derived & rhs)
    : Base(rhs)//显式调用基类的拷贝构造函数
    , _derived(rhs._derived)
    {
        cout << "Derived的拷贝构造" << endl;
    }

    Derived & operator=(const Derived & rhs){
        Base::operator=(rhs);//显式调用基类的赋值运算符函数
        _derived = rhs._derived;
        cout << "Derived的赋值运算符函数" << endl;
        return *this;
    }

    void print() const{
        cout << "_base:" << _base << endl;
        cout << "_derived:" << _derived << endl;
    }

private:
    long _derived = 12;
};

void test0(){
    Derived d1(10,7);
    Derived d2 = d1;
    d2.print();

    Derived d3(4,5);
    d1 = d3;
    d1.print();
}

int main(void){
    test0();
    return 0;
}
